package com.group11.user.controller;

import com.group11.common.pojo.ResponseResult;
import com.group11.user.entity.User;
import com.group11.user.service.UserService;
import com.group11.user.vo.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class InfoController {
    @Autowired
    UserService userService;

    @PostMapping("getUserInfo")
    public ResponseResult<UserInfoVO> getUserInfo(@RequestHeader Integer id){
      log.debug("id:{}",id);
      User user=userService.getById(id);
      UserInfoVO userInfoVO = new UserInfoVO();
      userInfoVO.setAccount(user.getAccount());
      userInfoVO.setAvatar(user.getAvatar());
      return new ResponseResult<>(userInfoVO);
    }

    @PostMapping("setUserType/{type}")
    public ResponseResult<Void> setUserType(@RequestHeader Integer id, @PathVariable String type){
        userService.setUserType(id,type);
        return ResponseResult.SUCCESS;

    }

    //上传头像时修改表数据
    @PostMapping("setUserAvatar")
    public ResponseResult<Void> setUserAvatar(@RequestHeader Integer id, @RequestParam("avatar") String avatar){
        userService.setUserAvatar(id,avatar);
        return ResponseResult.SUCCESS;
    }
}
